package com.ruoyi.tcsp.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.tcsp.domain.bean.req.TcspExpertInfoReq;
import com.ruoyi.tcsp.domain.mysql.TcspExpertInfo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.tcsp.service.ITcspExpertInfoService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 专家智库Controller
 * 
 * @author ruoyi
 * @date 2025-04-15
 */
@RestController
@RequestMapping("/tcsp/expert")
public class TcspExpertInfoController extends BaseController
{
    @Autowired
    private ITcspExpertInfoService tcspExpertInfoService;

    /**
     * 查询专家智库列表
     */
    @PreAuthorize("@ss.hasPermi('tcsp:expert:list')")
    @GetMapping("/list")
    public TableDataInfo list(TcspExpertInfo tcspExpertInfo)
    {
        startPage();
        List<TcspExpertInfo> list = tcspExpertInfoService.selectTcspExpertInfoList(tcspExpertInfo);
        return getDataTable(list);
    }

    /**
     * 导出专家智库列表
     */
    @PreAuthorize("@ss.hasPermi('tcsp:expert:export')")
    @Log(title = "专家智库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TcspExpertInfo tcspExpertInfo)
    {
        List<TcspExpertInfo> list = tcspExpertInfoService.selectTcspExpertInfoList(tcspExpertInfo);
        ExcelUtil<TcspExpertInfo> util = new ExcelUtil<TcspExpertInfo>(TcspExpertInfo.class);
        util.exportExcel(response, list, "专家智库数据");
    }

    /**
     * 获取专家智库详细信息
     */
    @PreAuthorize("@ss.hasPermi('tcsp:expert:query')")
    @GetMapping(value = "/{expertId}")
    public AjaxResult getInfo(@PathVariable("expertId") Long expertId)
    {
        return success(tcspExpertInfoService.selectTcspExpertInfoByExpertId(expertId));
    }

    /**
     * 新增专家智库
     */
    @PreAuthorize("@ss.hasPermi('tcsp:expert:add')")
    @Log(title = "专家智库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TcspExpertInfoReq req)
    {
        LoginUser loginUser = getLoginUser();
        AjaxResult ajax = toAjax(tcspExpertInfoService.insertTcspExpertInfo(req, loginUser));
        return ajax;
    }

    /**
     * 修改专家智库
     */
    @PreAuthorize("@ss.hasPermi('tcsp:expert:edit')")
    @Log(title = "专家智库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TcspExpertInfoReq req)
    {
        LoginUser loginUser = getLoginUser();
        return toAjax(tcspExpertInfoService.updateTcspExpertInfo(req, loginUser));
    }

    /**
     * 删除专家智库
     */
    @PreAuthorize("@ss.hasPermi('tcsp:expert:remove')")
    @Log(title = "专家智库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{expertIds}")
    public AjaxResult remove(@PathVariable Long[] expertIds)
    {
        return toAjax(tcspExpertInfoService.deleteTcspExpertInfoByExpertIds(expertIds));
    }
}
